package io.renren.modules.jxgkteacher.service.Impl;

import io.renren.modules.jxgkteacher.dao.TeacherCourseMapper;
import io.renren.modules.jxgkteacher.entity.TeacherCourseEntity;
import io.renren.modules.jxgkteacher.service.TeacherCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TeacherCourseServiceImpl implements TeacherCourseService {
    @Autowired
    TeacherCourseMapper teacherCourseMapper;
    public List<TeacherCourseEntity> FindTeacherWeekCourseById(String teacherId,
                                                              String courseAcademicYear,
                                                              String courseAcademicTerm,
                                                              String courseWhichWeek)
    {
        List<TeacherCourseEntity> param=teacherCourseMapper.FindTeacherWeekCourseById(teacherId,courseAcademicYear,courseAcademicTerm,courseWhichWeek);
        List<TeacherCourseEntity> result=new ArrayList<>();
        TeacherCourseEntity temp=new TeacherCourseEntity();
        boolean same=false;
        for(TeacherCourseEntity temp1:param){
            same=false;
            for(TeacherCourseEntity temp2:result){
                if(temp2.getCourseWhichDay().equals(temp1.getCourseWhichDay())
                        &&temp2.getCourseWhichIndex().equals(temp1.getCourseWhichIndex())
                        &&temp2.getCourseName().equals(temp1.getCourseName())
                        &&!temp2.getClassName().equals(temp1.getClassName()) ){
                    temp2.setClassName(temp1.getClassName()+","+temp2.getClassName());
                    temp2.setClassCourseId(temp1.getClassCourseId()+","+temp2.getClassCourseId());
                    same=true;
                }

            }
            if(same==false){
                result.add(temp1);
            }
        }
        return  result;
    }
    public List<TeacherCourseEntity> FindTeacherCourseByTime( String teacherId,  String courseTime){
        return teacherCourseMapper.FindTeacherCourseByTime(teacherId,courseTime);
    }

}
